package com.hisicom.scqxspxcjc.services;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.hisicom.scqxspxcjc.sceneCheck.resultDecision.domain.ResultDecisionBusiness;
import com.hisicom.scqxspxcjc.sceneCheck.resultDecision.exception.ResultDecisionException;
import com.hisicom.scqxspxcjc.sceneCheck.resultDecision.service.ResultDecisionBusinessService;
import com.hisicom.scqxspxcjc.sceneCheck.resultDecision.service.ResultDecisionService;
import com.hisicom.scqxspxcjc.sceneCheck.systemCheck.domain.SystemCheck;
import com.hisicom.scqxspxcjc.sceneCheck.systemCheck.service.SystemCheckService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * @author zhonggls
 * @date 2023/9/27 09:50
 * @Explain
 */
@Service
@Transactional
public class ResultDecisionServiceBus {
    @Autowired
    private ResultDecisionBusinessService resultDecisionBusinessService;
    @Autowired
    private SystemCheckService systemCheckService;
    @Autowired
    private ResultDecisionService resultDecisionService;

    /**
     * 通过组id获取"缺陷和问题描述"栏对象集合
     *
     * @param groupId 分组id
     * @return "缺陷和问题描述"栏对象集合
     */
    public Object findResultDecisionList(String groupId) {
        if (StrUtil.isBlank(groupId)) {
            throw new ResultDecisionException("系统未获取到分组id，请联系管理员");
        }
        List<ResultDecisionBusiness> resultDecisionBusinessList = resultDecisionBusinessService.findByGroupIdOrderBySort(groupId);
        //如果不为空直接返回
        if (ObjectUtil.isNotEmpty(resultDecisionBusinessList)) {
            return resultDecisionBusinessList;
        }
        //为空返回模版核查结果数据
        return resultDecisionService.findAllNoId();
    }
    /**
     * 通过组id获取缺陷项
     * @param groupId 组id
     * @return
     */
    public Object findByGroupIdAndResultNo(String groupId) {
        List<ResultDecisionBusiness> resultDecisionBusinessList = resultDecisionBusinessService.findByGroupIdAndResultNo(groupId, "1");
        if(resultDecisionBusinessList.size()==0){
           List <SystemCheck> systemCheckList= systemCheckService.findByGroupId(groupId);
        }
        
        return resultDecisionBusinessList;
    }

    /**
     * 保存"缺陷和问题描述" 对象集合
     *
     * @param params "缺陷和问题描述"对象集合数据
     * @return 成功/失败
     */
    public void addDecisionBusiness(Map params) {
        resultDecisionBusinessService.addDecisionBusiness(params);
    }
}
